#pragma once

#include "Vertex.h"

namespace rt
{
	struct Material;

	struct __declspec(align(16)) IntersectionData
	{
		XMVECTOR Normal;
		XMVECTOR TexCoords;
		Material * Material;
	};

	struct Ray
	{
		OVERRIDE_NEW_DELETE_WITH_ALIGNMENT(16)
		//Ray(Vec3 o = Vec3(0,0,0), Vec3 d = Vec3(0,0,1))
		//	: _origin(o), _direction(d)
		//{}
		//Vec3 _origin;
		//Vec3 _direction;
		Ray(XMFLOAT3 o = XMFLOAT3(0,0,0), XMFLOAT3 d = XMFLOAT3(0,0,1))
			: Orig(XMLoadFloat3(&o)), Dir(XMLoadFloat3(&d))
		{}
		Ray(XMVECTOR orig, XMVECTOR dir)
			: Orig(orig), Dir(dir)
		{}

		XMVECTOR Orig;
		XMVECTOR Dir;
	};

	struct Ray4_SingleOrigin
	{
		XMVECTOR Orig;
		XMVECTOR DirX, DirY, DirZ;
		XMVECTOR GetDir(uint index) const
		{
			return XMVectorSet(XMVectorGetByIndex(DirX, index), XMVectorGetByIndex(DirY, index), XMVectorGetByIndex(DirZ, index), 0.0f);
		}
	};

	struct Ray4
	{
		Ray4(){}
		Ray4(const Ray4_SingleOrigin & p)
		{
			DirX = p.DirX;
			DirY = p.DirY;
			DirZ = p.DirZ;
			OrigX = XMVectorReplicate(XMVectorGetX(p.Orig));
			OrigY = XMVectorReplicate(XMVectorGetY(p.Orig));
			OrigZ = XMVectorReplicate(XMVectorGetZ(p.Orig));
		}

		XMVECTOR OrigX, OrigY, OrigZ;
		XMVECTOR DirX, DirY, DirZ;

		void SetRay(XMVECTOR orig, XMVECTOR dir, uint index)
		{
			OrigX = XMVectorSetByIndex(OrigX, XMVectorGetX(orig), index);
			OrigY = XMVectorSetByIndex(OrigY, XMVectorGetY(orig), index);
			OrigZ = XMVectorSetByIndex(OrigZ, XMVectorGetZ(orig), index);
			DirX = XMVectorSetByIndex(DirX, XMVectorGetX(dir), index);
			DirY = XMVectorSetByIndex(DirY, XMVectorGetY(dir), index);
			DirZ = XMVectorSetByIndex(DirZ, XMVectorGetZ(dir), index);
		}

		XMVECTOR GetOrig(uint index) const
		{
			return XMVectorSet(XMVectorGetByIndex(OrigX, index), XMVectorGetByIndex(OrigY, index), XMVectorGetByIndex(OrigZ, index), 0.0f);
		}
		XMVECTOR GetDir(uint index) const
		{
			return XMVectorSet(XMVectorGetByIndex(DirX, index), XMVectorGetByIndex(DirY, index), XMVectorGetByIndex(DirZ, index), 0.0f);
		}
	};
}

